<template>
	<view>
		<!-- 头部提示 -->
		<!-- <navbar :backshow="false" :title="title" :navBarHeight="navBarHeight" :menuRight="menuRight" :menuTop="menuTop"
			:menuHeight="menuHeight"></navbar> -->

		<!-- 头部展位 -->
		<view class="userboxbj">
			<view class="userimg">
				<image src="@/static/usericon.png" mode=""></image>
			</view>
			<view class="togologin" @click="loginto">
				<image src="@/static/qhlogin.png" mode=""></image>
				切换账号
			</view>
		</view>
		<view class="userdatamain">
			<view class="userdataitem">
				<view class="userdataicon">
					<image src="@/static/userid.png" mode=""></image>
				</view>
				<view class="userdatades">
					<view class="userdesname">工号/学号</view>
					<view class="userdes">
						{{ user.username }}
					</view>
				</view>
			</view>
			<view class="userdataitem">
				<view class="userdataicon">
					<image src="@/static/username.png" mode=""></image>
				</view>
				<view class="userdatades">
					<view class="userdesname">用户姓名</view>
					<view class="userdes">
						{{ user.nickname }}
					</view>
				</view>
			</view>
			<view class="userdataitem">
				<view class="userdataicon">
					<image src="@/static/userly.png" mode=""></image>
				</view>
				<view class="userdatades">
					<view class="userdesname">用户类型</view>
					<view class="userdes">
						{{ displayChineseRole(user.userType) }}
					</view>
				</view>
			</view>
			<view class="userdataitem">
				<view class="userdataicon">
					<image src="@/static/userbooking.png" mode=""></image>
				</view>
				<view class="userdatades" @click="classfnd">
					<view class="userdesname">预约记录</view>
					<view class="userdes">
						{{ bookingnumber == null ? "0" : bookingnumber }}条
						<uni-icons type="right" size="23"></uni-icons>
					</view>
				</view>
			</view>
			<view class="userdataitem" @click="classfn">
				<view class="userdataicon">
					<image src="@/static/userclass.png" mode=""></image>
				</view>
				<view class="userdatades">
					<view class="userdesname">班级</view>
					<view class="userdes">
						<span>{{ user.organizationName }}</span>
						<uni-icons type="right" size="23"></uni-icons>
					</view>
				</view>
			</view>

			<view class="userdataitem" @click="credfn">
				<view class="userdataicon">
					<image src="@/static/userxy.png" mode=""></image>
				</view>
				<view class="userdatades">
					<view class="userdesname">信用分值</view>
					<view class="userdes">
						<span>{{ user.userCredit }}分</span>
						<uni-icons type="right" size="23"></uni-icons>
					</view>
				</view>
			</view>
			<view class="userdataitem" @click="notilfn">
				<view class="userdataicon">
					<image src="@/static/usertil.png" mode=""></image>
				</view>
				<view class="userdatades">
					<view class="userdesname">通知公告</view>
					<view class="userdes">
						<span>{{ notilenb == null ? 0 : notilenb }}条未读</span>
						<uni-icons type="right" size="23"></uni-icons>
					</view>
				</view>
			</view>
		</view>
		<!-- <view class="main" :style="{ height: mainheight + 'px' }">123</view> -->

		<tabar current="2"></tabar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// title: "个人中心",
				// navBarHeight: 0, // 导航栏高度
				// menuRight: 0, // 胶囊距右方间距（方保持左、右间距一致）
				// menuTop: 0, // 胶囊距底部间距（保持底部间距一致）
				// menuHeight: 0, // 胶囊高度（自定义内容可与胶囊高度保证一致）
				// mainheight: 0,
				user: {},
				bookingnumber: "",
				notilenb: "",
			};
		},
		onLoad() {
			// const that = this;
			// // 获取系统信息
			// const systemInfo = wx.getSystemInfoSync();
			// // 胶囊按钮位置信息
			// const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
			// // 导航栏高度 = 状态栏高度 + 44
			// that.navBarHeight = systemInfo.statusBarHeight + 44;
			// that.menuRight = systemInfo.screenWidth - menuButtonInfo.right;
			// that.menuTop = menuButtonInfo.top;
			// that.menuHeight = menuButtonInfo.height;
			// that.mainheight = menuButtonInfo.top + menuButtonInfo.height;
			this.$myRequest({
				url: "/client/appointmentUser/userInfo",
			}).then((res) => {
				console.log("获取用户信息", res.data);
				this.user = res.data;
				uni.setStorage("classname", res.data.organizationName);
			});
			this.$myRequest({
				url: "/client/appointmentUser/appointmentNumber",
			}).then((res) => {
				console.log("获取预约数量", res.data);
				this.bookingnumber = res.data;
				// this.user = res.data
			});
			this.$myRequest({
				url: "/client/appointmentUser/noReadNotify",
			}).then((res) => {
				console.log("获取未读公告", res.data);
				this.notilenb = res.data;
				// this.user = res.data
			});
		},
		onShow() {
			this.$myRequest({
				url: "/client/appointmentUser/noReadNotify",
			}).then((res) => {
				console.log("获取未读公告", res.data);
				this.notilenb = res.data;
				// this.user = res.data
			});
		},
		methods: {
			classfnd() {
				uni.navigateTo({
					url: "/pages/bookingjl/bookingjl",
				});
			},

			loginto() {
				uni.setStorageSync("token", "");
				// 强制跳转至登录页
				uni.reLaunch({
					url: "/pages/index/index",
					fail(e) {
						console.error(e);
					},
				});
			},
			notilfn() {
				uni.navigateTo({
					url: "/pages/noticelist/noticelist",
				});
			},
			credfn() {
				uni.navigateTo({
					url: "/pages/credit/credit",
				});
			},
			classfn() {
				uni.navigateTo({
					url: "/pages/classlist/classlist",
				});
			},
			displayChineseRole(role) {
				switch (role) {
					case "TEACHER":
						return "老师";
					case "STUDENT":
						return "学生";
					case "VISITOR":
						return "访客";
					default:
						return "未知角色";
				}
			},
		},
	};
</script>

<style></style>